<?php
			ob_start();			
?>
<?php
		
		if (isset($_COOKIE["user"])) {
			// if cookie <> ""
		  }
		  else
		  {
			   header("location:login.php");
			  
		  }
?>
<!-- begin ckeidtor -->
<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({			 
	theme : "advanced",
	mode : "textareas",
    plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,code,forecolor,backcolor",
	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,fullscreen,insertfile,insertimage",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : true,
	theme_advanced_font_sizes : "10px,12px,14px,16px,24px",
});
</script>
<!-- end cheditor-->
<?php
	// get contac id
	@$con_id=$_REQUEST["con_id"];
	// when submit is click to reply mail
    if(isset($_POST["btnsubmit"]))
	{
		
		$con_id=$_POST["txthide"];
		//get message to send
		$message = escapeValue($_POST["txtmessage"]);
		//set mail sender and subject of mail
		$from = "doorProject.fr";
		$subject = "doorProject.fr";
			
		if($message=="")
		{
			errorMessage("Message ne peut pas être .. vides!");
		}else
		{
				//select all email from DB
			$sql="SELECT * FROM tbl_contact WHERE reply=1 AND con_id=".$con_id;
			$result=query($sql);

			$row=fetch_assoc($result);
			
				// set the mail will send to
			$to = $row["email"];
				
			   //end of message
				$headers  = "From: $from\r\n";
				$headers .= "Content-type: text/html\r\n";
			
				//options to send to cc+bcc
				//$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
				//$headers .= "Bcc: [email]email@maaking.cXom[/email]";
				
				// now lets send the email.
				$send_contact = mail($to, $subject, $message, $headers);

				if($send_contact){
					
					errorMessage("Répondre avec succès......!");
					//pageRedirect("contact_detail.php?con_id=$con_id","");
				}
				else
				{
					errorMessage("ERROR");
				}
				
			}// end sms !=""
			
		}// isset
	
?> 
                	<div id="border_cont_title">
                        	<div id='content_title_left'>gestion des contacts</div>
                            <div id='content_title_right'></div>
					</div> <!--end border_cont_title-->
                    
                    <form action="index.php?page=contact_detail" method="post" name="frmcontact_detail">
                       <input type="hidden" name="txthide" value="<?php echo $con_id; ?>"  />
                        <table width="100%">
                        	<tr>
                            	<td width="30%">Message de réponse:</td>
                                <td width="70%"><textarea name="txtmessage" class="ckeditor" cols="40" rows="10" id="txtmessage" wrap="virtual"></textarea></td>
                            </tr>
                       
                       		<tr>
                            	<td colspan="2">
                                	 <input  style="float:right; height:35px; width:100px;" type="submit" name="btnsubmit" value="Répondre"  />
                                </td>
                            </tr>
                        </table>
                    </form>
                    <br/>
                    <?php echo @$errors;?>
                    	<table width="770px">
                            	<tr>
                                    <th>Nom</th>
                                    <th>E-mail </th>
                                    <th>Message</th>
                                </tr>
                             
                                <?php
									
                                    $sql = "SELECT * from  tbl_contact WHERE con_id='$con_id'"; 
                                    $result = query($sql);
								
                                    $row = fetch_assoc($result);
                                   
                                ?>
                                <tr>
                                	<td align="center" width="130px"><?php echo $row["name"];?></td>
                                    <td align="center" width="130px"><?php echo $row["email"];?></td>
                                    <td align="left" width="510px"><?php echo $row["message"]; ?></td>
                                </tr>
                                <?php
									

                                ?>
                            </table>
                         <!--end table -->